<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<div id="spanner"></div>
<script>
var styleCount, layoutCount;

setPrintTestResultsLazily();

function assertSyncLayout(sync) {
    if (window.internals) {
        styleCount = internals.updateStyleAndReturnAffectedElementCount();
        layoutCount = internals.needsLayoutCount();
        // scrollTo should have synchronously updated style and layout
        if (sync) {
            shouldBe("styleCount", "0");
            shouldBe("layoutCount", "0");
        } else {
            shouldNotBe("styleCount", "0");
            shouldNotBe("layoutCount", "0");
        }
    }
}

spanner.style.width = "3000px";
spanner.style.height = "3000px";
scrollTo({ left: 0, top: 1000});
assertSyncLayout(true);
shouldBe("window.scrollY", "1000");

scrollTo({ left: 1000, top: 1000});
assertSyncLayout(true);
shouldBe("window.scrollX", "1000");

spanner.style.height = "2000px";
scrollTo({ left: 0, top: 0});
assertSyncLayout(false);
shouldBe("window.scrollY", "0");

spanner.style.height = "1px";
scrollTo({ left: 0 });
assertSyncLayout(true);

spanner.style.height = "2px";
scrollTo({ top: 0 });
assertSyncLayout(true);

spanner.style.height = "3px";
scrollTo({ });
assertSyncLayout(true);
</script>
